﻿using jianvgroup.com.Models;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace jianvgroup.com.Extensions
{
    public static class HtmlHelperExtensions
    {
        /// <summary>
        /// GET 形式分页
        /// </summary>
        /// <param name="urlHelper"></param>
        /// <param name="pageModel"></param>
        /// <param name="index"></param>
        /// <param name="isCurrentIndex"></param>
        /// <param name="isDisable"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public static HtmlString CreatePageListTag(this IUrlHelper urlHelper,
                                                     BasePageModel pageModel,
                                                     int index,
                                                     bool isCurrentIndex = false,
                                                     bool isDisable = true,
                                                     string content = "")
        {
            string url = urlHelper.Action(pageModel.ActionName, new { searchkey = pageModel.SearchKeyWord, pageIndex = index, id = pageModel.id });
            string activeClass = !isCurrentIndex ? string.Empty : "class='active'";
            string disableClass = isDisable ? string.Empty : "class='disabled'";
            url = isDisable ? "href='" + url + "'" : string.Empty;
            string contentString = string.IsNullOrWhiteSpace(content) ? index.ToString() : content;

            return new HtmlString("<li " + activeClass + disableClass + "><a " + url + ">" + contentString + "</a></li>");

        }

        public static HtmlString PageListTag(this IUrlHelper urlHelper, BasePageModel pageModel, int index, bool isCurrentIndex = false, bool isDisable = true, string content = "")
        {
            string activeClass = !isCurrentIndex ? string.Empty : "class='active'";
            string disableClass = isDisable ? string.Empty : "class='disabled'";
            string contentString = string.IsNullOrEmpty(content) ? index.ToString() : content;
            if (isDisable)
            {
                return new HtmlString("<li " + activeClass + disableClass + "><a onclick='ajaxPage(" + index + ")'>" + contentString + "</a></li>");
            }
            else
            {
                return new HtmlString("<li " + activeClass + disableClass + "><a>" + contentString + "</a></li>");
            }
        }
    }
}
